/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.book.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.book.entity.BookCategory;
import com.jeesite.modules.book.service.BookCategoryService;

/**
 * book_category 书籍分类表Controller
 * @author 逗你玩
 * @version 2019-07-21
 */
@Controller
@RequestMapping(value = "${adminPath}/book/bookCategory")
public class BookCategoryController extends BaseController {

	@Autowired
	private BookCategoryService bookCategoryService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public BookCategory get(String id, boolean isNewRecord) {
		return bookCategoryService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("book:bookCategory:view")
	@RequestMapping(value = {"list", ""})
	public String list(BookCategory bookCategory, Model model) {
		model.addAttribute("bookCategory", bookCategory);
		return "modules/book/bookCategoryList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("book:bookCategory:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<BookCategory> listData(BookCategory bookCategory, HttpServletRequest request, HttpServletResponse response) {
		bookCategory.setPage(new Page<>(request, response));
		Page<BookCategory> page = bookCategoryService.findPage(bookCategory);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("book:bookCategory:view")
	@RequestMapping(value = "form")
	public String form(BookCategory bookCategory, Model model) {
		model.addAttribute("bookCategory", bookCategory);
		return "modules/book/bookCategoryForm";
	}

	/**
	 * 保存book_category 书籍分类表
	 */
	@RequiresPermissions("book:bookCategory:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated BookCategory bookCategory) {
		bookCategoryService.save(bookCategory);
		return renderResult(Global.TRUE, text("保存book_category 书籍分类表成功！"));
	}
	
	/**
	 * 删除book_category 书籍分类表
	 */
	@RequiresPermissions("book:bookCategory:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(BookCategory bookCategory) {
		bookCategoryService.delete(bookCategory);
		return renderResult(Global.TRUE, text("删除book_category 书籍分类表成功！"));
	}
	
}